package com.aioething.iot.model;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import lombok.Data;

import java.util.Date;

@Data
public class Equipment {
    private String equipmentId;
    private String productId;
    private String deviceName;
    private String psk;
    private String tags;
    private String version;
    private String iccid;
    private JSONObject reported;
    private JSONObject desired;
    private JSONObject delta;
    private Integer status;
    private Date onlineTime;
    private Date offlineTime;
    private Boolean deleteFlag;
    private Date createTime;

    public String getEquipmentId() {
        return ObjectUtil.isEmpty(equipmentId) ? productId.concat("/").concat(deviceName) : equipmentId;
    }

    public String getProductId() {
        return ObjectUtil.isEmpty(productId) ? equipmentId.split("/")[0] : productId;
    }

    public String getDeviceName() {
        return ObjectUtil.isEmpty(deviceName) ? equipmentId.split("/")[1] : deviceName;
    }
}
